package com.techsoul.admin.controller;

import com.techsoul.admin.service.IGoodsService;
import com.techsoul.common.core.pojo.Result;
import com.techsoul.module.goods.pojo.param.SpuSaveParam;
import com.techsoul.module.goods.pojo.param.SpuSearchParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品 控制器
 *
 * @author liuen
 */
@Api(tags = "商品")
@RestController
@RequestMapping("/api/goods")
public class SingleGoodsController {

    @Autowired
    private Result result;

    @Autowired
    private IGoodsService goodsService;

    @ApiOperation("添加商品访问记录")
    @PostMapping("/addView/{id}")
    public Result addView(@PathVariable("id") String id) {
        goodsService.addView(id);
        return result.success();
    }

    @ApiOperation("根据SpuId获取商品详情")
    @GetMapping("/getSpu/{spuId}")
    public Result goodsDetailBySpuId(@PathVariable("spuId") String spuId) {
        return result.success(goodsService.goodsDetailBySpuId(spuId));
    }

    @ApiOperation("根据SkuId获取商品详情")
    @GetMapping("/getSku/{skuId}")
    public Result goodsDetailBySkuId(@PathVariable("skuId") String skuId) {
        return result.success(goodsService.goodsDetailBySkuId(skuId));
    }

    @ApiOperation("商品列表-分页")
    @PostMapping("/search/{current}/{pageSize}")
    public Result search(@RequestBody SpuSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(goodsService.search(params, current, pageSize));
    }

    @ApiOperation("分类商品列表")
    @PostMapping("/search/categoryGoodsList")
    public Result categoryGoodsList() {
        return result.success(goodsService.categoryGoodsList());
    }

    @ApiOperation("用户商品记录列表")
    @PostMapping("/search/viewList/{current}/{pageSize}")
    public Result viewList(@PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(goodsService.viewList(current, pageSize));
    }

}
